<template>
    <div class="layout-content">
        <div class="layout-content-main">
            <Breadcrumb class="content-title mbt1">
                <BreadcrumbItem>日志服务</BreadcrumbItem>
            </Breadcrumb>
            <div class="section">
                <div class="section-title">
                    日志服务
                </div>
                <Row class="mbt4">
                    <Col span="6">    
                        <!-- <Input placeholder="请输入添加时间" v-model="searchValue"> -->
                        <i-col span="24">
                          <Date-picker  type="date" placeholder="请输入起始查询日期" style="width: 200px" @on-change="chooseData"></Date-picker>
                        </i-col>

                        <Button slot="append" icon="ios-search" @click="search()"></Button>
                        </Input>
                    </Col>
               </Row>
                <Table border :columns="columns7" :data="logList" class="mbt4" :page-size='9'></Table>
                <Page :total="logListNum" show-total class="center" @on-change="changePage" :page-size="9"></Page>
                
            </div>
        </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 9,
      logList: [],
      logListNum: 0,
      searchValue:'',

      columns7: [
        {
          title: "添加时间",
          key: "createTime",
          align: "center",
          width: "300",
          render: (h, params) => {
           
           //console.log(this.translateTime(new Date(params.row.createTime)))
           return this.translateTime(new Date(params.row.createTime))
            
          }
        },
        {
          title: "操作人",
          key: "createUserName",
          align: "center",
          render: (h, params) => {
            if(params.row.createUserName==null){
              return "暂无"
            }else{
              return params.row.createUserName
            }
          }
        },

        {
          title: "日志内容",
          key: "remark",
          align: "center"
        },
        {
          title: "操作",
          key: "action",
          width: 400,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      // this.show(params.index)
                      //this.chooseJurisdictionModal = true;
                      this.remove(params);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ]
    };
  },
  mounted() {
    this.getLogList(this.pageNum, this.pageSize,'');
  },
  methods: {
    //获取日志列表
    getLogList(pageNum, pageSize,searchValue) {
      this.$ajax
        .post(
          "/api/operationLog/info/queryOperationLog",
          `pageNum=${pageNum}&pageSize=${pageSize}&createTime=${searchValue}`
        )
        .then(response => {
          if (response.data.code == 1) {
            this.logList = response.data.resdata.list;
            this.logListNum = response.data.resdata.total;
          } else {
            this.$Modal.error({
              title: "错误",
              content: eresponse.data.msg
            });
          }
        })
        .catch(error => {
          this.$Modal.error({
            title: "错误",
            content: error
          });
        });
    },
    search(){
       this.getLogList(this.pageNum, this.pageSize,this.searchValue);
    },
    remove(params) {
      this.$Modal.confirm({
        title: "警告",
        content: "<p>确定要删除吗？删除后将无法恢复 !</p>",
        onOk: () => {
          this.$ajax
            .post(
              "/api/operationLog/info/deleteOperationLog",
              `operationId=${params.row.operationId}`
            )
            .then(response => {
                //console.log(response.data)
              if (response.data.code == 1) {
                this.$Message.success(response.data.msg);
                this.logList.splice(params.index, 1);
              }else{
                this.$Modal.error({
                    title: "错误",
                    content: response.data.msg
                });
              }
            })
            .catch(error => {
              this.$Modal.error({
                title: "错误",
                content: error
              });
            });
        }
      });
    },
    translateTime(now) {
				var year = now.getFullYear();
				var month = now.getMonth() + 1;
				var date = now.getDate();
				var hour = now.getHours();
				var minute = now.getMinutes();
				return year + "-" + this.judeZero(month) + "-" + this.judeZero(date)

			},
			judeZero(time) {
				return time < 10 ? '0' + time : time
			},
    //分页
    changePage(data) {
      //console.log(data);
      this.getLogList(data, this.pageSize,this.searchValue);
      
    },
    //日期回调
    chooseData(time){
        //console.log(data)
      this.searchValue = time;
      this.getLogList(this.pageNum, this.pageSize,time)
    }
  }
};
</script>

<style>
.emial-content {
  line-height: 30px;
  height: 323px;
  overflow: auto;
}
</style>
